package net.zjitc.utils;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class MD5Util {
    //MD5加密 加盐加密
    public static String hashPasswordWithSalt(String password,String salt) {
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            md.update(salt.getBytes());
            byte[] messageDigest = md.digest(password.getBytes());
            return bytesToHex(messageDigest);

        }catch (NoSuchAlgorithmException e) {
            throw  new RuntimeException(e);
        }

    }

    private static String bytesToHex(byte[] bytes) {
        StringBuilder result = new StringBuilder();
        for (byte b : bytes) {
            result.append(String.format("%02x",b));
        }
        return result.toString();
    }
}
